from builtins import range
from math import inf

n, m, s, d = map(int, input().split())
fires = list(map(int, input().split()))
path = []
w = [[inf if _ != _i else 0 for _i in range(n)] for _ in range(n)]
for i in range(m):
    _a, _b, _l = map(int, input().split())
    w[_a][_b] = _l
    w[_b][_a] = _l


def djstr(s, v):
    book = [False for _ in range(n)]  # 是否已经最小
    dist = [w[s][_] for _ in range(n)]  # s到其他节点的最小距离
    midpath = [-1 for _ in range(n)]
    firesum = [fires[0] for i in range(n)]
    book[s] = True
    dist[s] = 0
    for i in range(n - 1):
        mind = inf
        for j in range(n):
            if not book[j] and dist[j] < mind:
                mind = dist[j]
                u = j
        book[u] = True
        for v in range(n):
            if dist[v] > dist[u] + w[u][v]:
                dist[v] = dist[u] + w[u][v]
                midpath[v] = u
    path.append(d)
    j = d
    while midpath[j] != -1:
        path.append(midpath[j])
        j = midpath[j]
    path.append(s)
    path.reverse()
    print(*path)


djstr(s, d)
